Completed
Push — master ( c7ea8a...8a62cc )
by Justin
01:44
created

module.exports   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
/**
2
 * RS extensions to Person
3
 */
4
module.exports = function(GedcomX){
5
  
6
  // Extend serialization properties
7
  GedcomX.Person.jsonProps.push('living', 'display');
8
  
9
  // Override init() so that we can deserialize normalized values
10
  var oldInit = GedcomX.Person.prototype.init;
11
  GedcomX.Person.prototype.init = function(json){
12
    oldInit.call(this, json);
13
    if(json){
14
      this.setLiving(json.living);
15
      this.setDisplay(json.display);
16
    }
17
  };
18
  
19
  /**
20
   * Set the living flag
21
   * 
22
   * @function setLiving
23
   * @instance
24
   * @memberof Person
25
   * @param {Boolean} living
26
   * @return {Person} this
27
   */
28
  GedcomX.Person.prototype.setLiving = function(living){
29
    this.living = living;
30
    return this;
31
  };
32
  
33
  /**
34
   * Get the living flag
35
   * 
36
   * @function getLiving
37
   * @instance
38
   * @memberof Person
39
   * @return {Boolean} living
40
   */
41
  GedcomX.Person.prototype.getLiving = function(){
42
    return this.living;
43
  };
44
  
45
  /**
46
   * Set the display properties
47
   * 
48
   * @function setDisplay
49
   * @instance
50
   * @memberof Person
51
   * @param {DisplayProperties} display
52
   * @return {Person} this
53
   */
54
  GedcomX.Person.prototype.setDisplay = function(display){
55
    if(display){
56
      this.display = GedcomX.DisplayProperties(display);
57
    }
58
    return this;
59
  };
60
  
61
  /**
62
   * Get the display properties
63
   * 
64
   * @function getDisplay
65
   * @instance
66
   * @memberof Person
67
   * @return {DisplayProperties}
68
   */
69
  GedcomX.Person.prototype.getDisplay = function(){
70
    return this.display;
71
  };
72
  
73
  /**
74
   * Get a person's preferred name, if one exists.
75
   * 
76
   * @function getPreferredName
77
   * @instance
78
   * @memberof Person
79
   * @return {Name}
80
   */
81
  GedcomX.Person.prototype.getPreferredName = function(){
82
    return this.getNames().find(function(n){
83
      return n.getPreferred();
84
    });
85
  };
86
  
87
};